from airtest.core.api import *
from support.const.state import *
class Device:
    @staticmethod
    def getScreenSize():
        width = G.DEVICE.display_info['width']
        height = G.DEVICE.display_info['height']
        if(height > width):
            return width,height
        return height,width
    @staticmethod
    def swipe(p1, p2, rect = None):
        screen_width, screen_height = Device.getScreenSize()
        x0 = int(p1[0] * screen_width)
        y0 = int(p1[1] * screen_height)
        x1 = int(p2[0] * screen_width)
        y1 = int(p2[1] * screen_height)
        shell("input swipe {} {} {} {} 1000".format(x0,y0,x1,y1))
        sleep(Global.WAIT_UI_TIMEOUT)
        swipe_rect = None
        if(rect):
            swipe_rect = []
            offset_x = int((p2[0] - p1[0]) * screen_width)
            offset_y = int((p2[1] - p1[1]) * screen_height)
            swipe_rect.append((max(rect[0][0] + offset_x, 0), max(rect[0][1] + offset_y, 0)))
            swipe_rect.append((max(rect[1][0] + offset_x, 0), max(rect[1][1] + offset_y, 0)))
        return swipe_rect
    @staticmethod
    def text(msg):
        shell("input text '{}'".format(msg))
